import time
from LX225BusServo_mi import LX225BusServo as BusServo
import serial

# 读取总线舵机信息

bus_servo = BusServo(serial.Serial('COM5', 115200, timeout=0.001)) 

def decode_hex(hex_str):
    #hex_str = ', '.join(f'0x{b:02x}' for b in hex_str)
    return hex_str
if __name__ == '__main__':
    #bus_servo.rename_servo(0xfe, 0x01)                  # 重命名舵机ID
    ID = bus_servo.get_servo_id()                     # 获取舵机ID 
    
    print('ID:', decode_hex(ID))           # 打印舵机ID 以16进制格式显示
    
    position = bus_servo.read_angle(0x04)             # 获取舵机位置
    print('Position:', decode_hex(position))                   # 打印舵机位置 以16进制格式显示
    
    vin = bus_servo.get_vin(0x04)                       # 获取舵机电压
    print('Vin:', decode_hex(vin), 'mV')                             # 打印舵机电压 以16进制格式显示
    
    temp = bus_servo.get_temp(0x04)                     # 获取舵机温度
    print('Temp:', decode_hex(temp), '°C')
